<script setup lang="ts">
import { useRouter } from 'vue-router';

const router = useRouter();
const props = defineProps<{ game: any; ownedGameIds: number[] }>();

function goDetail() {
  const gameId = props.game.id || props.game.gameId;
  if (props.ownedGameIds.includes(gameId)) {
    // 跳转到游戏库并高亮该游戏
    router.push({ path: '/gamelibrary', query: { highlight: gameId } });
  } else {
    router.push(`/game-detail?id=${gameId}`);
  }
}

function getCoverUrl() {
  if (!props.game?.pic) return '';
  const base = props.game.pic.endsWith('/') ? props.game.pic : `${props.game.pic}/`;
  return `${base}assets/main/game-logo.svg`;
}
</script>

<template>
  <div class="mall-game-card" @click="goDetail">
    <img :src="getCoverUrl()" alt="封面" class="mall-game-card__img" />
    <div class="mall-game-card__info">
      <div class="mall-game-card__title">{{ game.gameName }}</div>
      <div class="mall-game-card__desc">{{ game.description }}</div>
      <div class="mall-game-card__price">￥{{ game.price }}</div>
      <div class="mall-game-card__score">评分：{{ game.score }}</div>
    </div>
  </div>
</template>

<style scoped>
.mall-game-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid #f0f0f0;
}
.mall-game-card:hover {
  box-shadow: 0 8px 24px rgba(0, 120, 215, 0.15);
  transform: translateY(-2px);
}
.mall-game-card__img {
  height: 160px;
  width: 100%;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #aaa;
  object-fit: cover;
}
.mall-game-card__info {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.mall-game-card__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #222;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.mall-game-card__desc {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
}
.mall-game-card__price {
  font-size: 18px;
  color: #0078d7;
  font-weight: 600;
  margin-bottom: 4px;
}
.mall-game-card__score {
  font-size: 14px;
  color: #ff9800;
  font-weight: 500;
}
</style>
